package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.rc.entity.UserRole;
import org.rc.mapper.UserRoleMapper;
import org.rc.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public void batchSave(List<UserRole> userRoles) {
        this.saveBatch(userRoles);
    }

    @Override
    public void saveUserRole(UserRole userRole) {
        this.save(userRole);
    }

    @Override
    public void deleteByUserId(Long userId) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>();
        qw.eq("user_id",userId);
        this.remove(qw);
    }

    @Override
    public void deleteByUserIds(List<Long> userIds) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>();
        qw.in("user_id",userIds);
        this.remove(qw);
    }

    @Override
    public List<UserRole> selectByRoleIds(List<Long> roleIds) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>();
        qw.in("role_id",roleIds);
        return this.list(qw);
    }

    @Override
    public List<UserRole> selectByUserIds(List<Long> userIds) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>();
        qw.in("user_id",userIds);
        return this.list(qw);
    }

    @Override
    public List<UserRole> selectByUserId(Long userId) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>();
        qw.eq("user_id",userId);
        return this.list(qw);
    }

    @Override
    public List<UserRole> selectByRoleId(Long roleId) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>();
        qw.eq("role_id",roleId);
        return this.list(qw);
    }
}
